#include "TPM_HAL_QE.h"
#include "Services_QE.h"

#define CONTROL_SURFACE_TIMER   3

#define AILERON_PWM_CHAN        0          
#define RUDDER_PWM_CHAN         1
#define ELEVATOR_PWM_CHAN       2

#define AILERON_PWM_DEFAULT     0
#define RUDDER_PWM_DEFAULT      0
#define ELEVATOR_PWM_DEFAULT    0

#define CSURFACE_MIN_VALUE      225
#define CSURFACE_CENTER_VALUE   375
#define CSURFACE_MAX_VALUE      525


#define CSURFACE_MIN_VALUE_HIGH  (CSURFACE_MIN_VALUE >> 8)
#define CSURFACE_MIN_VALUE_LOW  (CSURFACE_MIN_VALUE & 0x00FF)  


#define CALIBRATE_AILERON_MIN   	0x01
#define CALIBRATE_AILERON_CENTER	0x03
#define CALIBRATE_AILERON_MAX   	0x05
#define CALIBRATE_RUDDER_MIN   		0x07
#define CALIBRATE_RUDDER_CENTER		0x09
#define CALIBRATE_RUDDER_MAX   		0x0B
#define CALIBRATE_ELEVATOR_MIN   	0x0D
#define CALIBRATE_ELEVATOR_CENTER  	0x0F
#define CALIBRATE_ELEVATOR_MAX   	0x11

#define SURFACE_RESTORE_CONFIG_REQ  0xFF

#define SURFACE_FEEDBACK_FAILURE    0x80
#define SURFACE_FEEDBACK_SUCCESS    0x40

#define SURFACE_AILERON_MIN_REQ     0x20
#define SURFACE_AILERON_MAX_REQ     0x10
#define SURFACE_RUDDER_MIN_REQ      0x08
#define SURFACE_RUDDER_MAX_REQ      0x04
#define SURFACE_ELEVATOR_MIN_REQ    0x02
#define SURFACE_ELEVATOR_MAX_REQ    0x01 

void vfnControlSurface_ConfigurePWM (void);

void vfnControlSurface_Adjust (void);

uint8 u8Csurface_SaveCalValue (uint8 u8selection);

uint8 u8Csurface_RestoreConfig (void);

void vfnCsurface_CalibrateMinMax (void);

void vfnControlSurface_Disable (void);